<?php if (!defined('THINK_PATH')) exit();?><!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
	<!-- <script src='/Public/jquery.min.js'></script> -->
  <script src="https://cdn.static.runoob.com/libs/jquery/2.1.1/jquery.min.js"></script>
  
	<script src='/Public/foundation/js/foundation.min.js'></script>
	<link rel="stylesheet" href="/Public/foundation/css/foundation.min.css">
  <script src='/Public/jquery.cityselect.js'></script>
  <script src='/Public/jquery.datetimepicker.full.js'></script>
  <link rel="stylesheet" href="/Public/jquery.datetimepicker.css">
   <script src="http://cdn.static.runoob.com/libs/foundation/5.5.3/js/vendor/modernizr.js"></script>
    <meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<nav class="top-bar" data-topbar>
  <ul class="title-area">
    <li class="name">
      <h1><a href="#">后台管理</a></h1>
    </li>
  </ul>

  <section class="top-bar-section">
    <ul class="right">
      <li><a href=""><?php echo (session('name')); ?></a></li>
      <li><a href="<?php echo U('Login/doLogout');?>">退出</a></li>
    </ul>
  </section>
</nav>

<div class="small-2 columns">
<ul class="side-nav">
 <?php if(is_array($nav)): $i = 0; $__LIST__ = $nav;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$vo): $mod = ($i % 2 );++$i;?><li><a href="<?php echo U($vo['url']);?>" target='<?php echo ($vo["target"]?"_blank":null); ?>'><?php echo ($vo["mname"]); ?></a></li><?php endforeach; endif; else: echo "" ;endif; ?>
    </ul>
</div>
<div class="small-10 columns">

<table id='Tbl'>
<thead>
	<tr>
		<th><input type="checkbox" onclick="selectAll(this)" value='全选'></th>
		<th>编号</th>
		<th>规则名称</th>
		<th>分值</th>
		<th>描述</th>
		<th>锁定</th>
		<th>操作</th>
	</tr>
	</thead>
	<tbody>
	<?php if(is_array($points_rule)): $i = 0; $__LIST__ = $points_rule;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$vo): $mod = ($i % 2 );++$i;?><tr id="row_<?php echo ($vo["point_rule_id"]); ?>">
			<td><input type="checkbox" class='select' value='<?php echo ($vo["point_rule_id"]); ?>' ></td>
			<td><?php echo ($vo["point_rule_id"]); ?></td>
			<td><input name="rule_name" class="clss" disabled type="text" value="<?php echo ($vo["rule_name"]); ?>"></td>
			<td><input name="val" class="clss" disabled type="text" value="<?php echo ($vo["val"]); ?>"></td>
			<td><input name="desc" class="clss" disabled  type="text" value="<?php echo ($vo["desc"]); ?>"></td>
                
			<td>
			
             <div class="switch tiny">
              <input onclick="lock(this)" value="<?php echo ($vo["point_rule_id"]); ?>" id="lock_<?php echo ($vo["point_rule_id"]); ?>" type="checkbox"  <?php echo ($vo['lock']?'checked':''); ?>>
                <label for="lock_<?php echo ($vo["point_rule_id"]); ?>"></label>
                </div>
               
			</td>
            <td>
			<button type="button" onclick='edit("<?php echo ($vo["point_rule_id"]); ?>")' class='edit'>编辑</button>
			<button style='display:none' onclick='save("<?php echo ($vo["point_rule_id"]); ?>")' type="button" class="save">保存</button>
			</td>
		</tr><?php endforeach; endif; else: echo "" ;endif; ?>
	</tbody>
</table>
<input type="button" class="button tiny" onclick="moreDel()" value='删除(批量)'>
<input type="button" class="button tiny" onclick="unSelect()" value='反选'>
<input type="button" class='button tiny' onclick="addMenu()" value='添加'>
<script>
        function selectAll(obj) {
            $('#Tbl tbody .select').prop('checked',$(obj).prop('checked'));
        }
        function unSelect() {
            $('#Tbl tbody .select').map(function(){
                $(this).prop('checked',!$(this).prop('checked'));
            });
        }
        function moreDel() {
            if(!confirm('确定删除吗?')){
                return;
            }
            var ids = $('#Tbl tbody .select:checked').map(function () {
                $(this).parent().parent().remove();
                return $(this).val();
            });
            ids  = ids.get().join();
            $.post('<?php echo U("doDelPointsRule");?>',{ids:ids},function (data) {
                if(data.error ==0)alert(data.msg);
            });
        }
        function lock(obj) {
            var id = $(obj).val();
            var lockval = $(obj).prop('checked')?1:0;
            $.post('<?php echo U("doEditPointsRule");?>',{point_rule_id:id,lock:lockval});
        }

        
        
        function edit(id) {
            $('#row_'+id+' .clss').prop('disabled',false);
            $('#row_'+id+' .edit').hide();
            $('#row_'+id+' .save').show();
        }

        function save(id) {
            $('#row_'+id+' .clss').prop('disabled',true);
            $('#row_'+id+' .edit').show();
            $('#row_'+id+' .save').hide();

            var data = {
                point_rule_id:id,
                rule_name:$('#row_'+id+' [name=rule_name]').val(),
                val:  $('#row_'+id+' [name=val]').val(),
                desc :  $('#row_'+id+' [name=desc]').val(),
            }

            $.post('<?php echo U("doEditPointsRule");?>',data,function (data) {
                if(data.error==0){
                    alert(data.msg);
                }
            });

        }
         function addMenu(){
            $.get("<?php echo U('lastId');?>", '',
            function(id){
               var id= parseInt(id)+1;

                var html =
            '<tr id="row_'+id+'">'+
'            <td><input type="checkbox" class="select" value="" ></td>'+
'            <td>'+id+'</td>'+
'            <td><input name="rule_name" class="clss" disabled type="text" value=""></td>'+
'            <td><input name="val" class="clss" disabled type="text" value=""></td>'+
'            <td><input name="desc" class="clss" disabled type="text" value=""></td>'+
'            <td>'+
'             <div class="switch tiny">'+
'              <input onclick="lock(this)" value="" id="lock_'+id+'" type="checkbox"  <?php echo ($vo["lock"]?"checked":""); ?>>'+
'                <label for="lock_'+id+'"></label>'+
'                </div>'+
'               '+
'            </td> '+
'            <td>'+
'            <button type="button" onclick="edit(\''+id+'\')" class="edit tiny">编辑</button>'+
'            <button style="display:none" onclick="save(\''+id+'\')" type="button" class="save tiny">保存</button>'+
'            </td>'+
'        </tr>';
 $('tbody').append(html);
            
            });

        }
</script>
</div>

</div>

</body>
</html>